package factory.simplefactory;

import factory.Eclipse;
import factory.IDevTool;
import factory.Idea;

/**
 * Created by thiswhyme on 2019/03/14
 */
public class DevToolFactory {

    /**
     * 简单创建
     * @param toolName
     * @return
     */
    public IDevTool getDevTool(String toolName) {
        if("eclipse".equals(toolName)) {
            return new Eclipse();
        } else if ("idea".equals(toolName)) {
            return new Idea();
        } else {
            return null;
        }
    }

    /**
     * 通过反射创建
     * @param c
     * @return
     */
    public IDevTool getDevTool(Class<? extends IDevTool> c) {
        IDevTool tool = null;
        if(c != null) {
            try {
                tool = c.newInstance();
            } catch (InstantiationException | IllegalAccessException e) {
                e.printStackTrace();
            }
        }
        return tool;
    }
}
